package com.aliyun.heiyu.powermaster.server.rotary.dao.impl;

import com.aliyun.heiyu.powermaster.server.rotary.dao.PduDAO;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.PduDataDynEntity;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.PduDataElectricEntity;
import com.aliyun.heiyu.powermaster.server.rotary.utils.JdbcUtil;

import java.util.List;
import java.util.Map;

/**
 * @Description pdu实现
 * @Author shun.zhang
 * @Date 2020/9/11 17:15
 **/
public class PduDAOImpl implements PduDAO {
    /**
     * 获取pdu设备
     *
     * @return
     */
    @Override
    public List<Map<String, String>> getPdus() {
        String sql = "SELECT device_id from device_common where type = 'pdu' and status = 1";
        return JdbcUtil.queryForListMap(sql, null);
    }

    /**
     * 获取pdu支路功率
     *
     * @param deviceId
     * @return
     */
    @Override
    public List<PduDataDynEntity> getPowerListByDeviceId(String deviceId) {
        String sql = "SELECT device_id,branch_number,branch_power from device_pdu_branch_power where 1= ? and device_id = ? ORDER by id desc LIMIT 24";
        Object[] obj = new Object[2];
        obj[0] = 1;
        obj[1] = deviceId;
        return JdbcUtil.queryForList(sql, obj, PduDataDynEntity.class);
    }

    /**
     * 获取pdu支路电流
     *
     * @param deviceId
     * @return
     */
    @Override
    public List<PduDataElectricEntity> getElectricListByDeviceId(String deviceId) {
        String sql = "SELECT device_id,branch_number,branch_electric from device_pdu_branch_electric where 1= ? and device_id = ? ORDER by id desc LIMIT 24";
        Object[] obj = new Object[2];
        obj[0] = 1;
        obj[1] = deviceId;
        return JdbcUtil.queryForList(sql, obj, PduDataElectricEntity.class);
    }

    /**
     * 获取pdu设备
     *
     * @param deviceId
     * @return
     */
    @Override
    public Map<String, String> getPduByDeviceId(String deviceId) {
        String sql ="SELECT id, guid, device_id, frequency, electric_current, voltage, active_power, no_work_power, inspecting_power, power_factor, active_energy, no_work_energy, create_time, update_time, del\n" +
            "FROM device_pdu_base where 1= ? and device_id = ? order by id desc limit 1";
        Object[] obj = new Object[2];
        obj[0] = 1;
        obj[1] = deviceId;
        return JdbcUtil.queryForMap(sql,obj);
    }
}
